using Indiefreaks.AceOnSteroids.Logic.Behaviors;
using Indiefreaks.Xna.Physics.Entities;
using Indiefreaks.Xna.Sessions;
using Microsoft.Xna.Framework.Graphics;
using SynapseGaming.LightingSystem.Rendering;

namespace Indiefreaks.AceOnSteroids.Entities
{
    /// <summary>
    /// The Asteroid game entity
    /// </summary>
    /// <remarks>An asteroid is rendered using a high poly model and we use a low poly model for the collision</remarks>
    public class Asteroid : SceneObject
    {
        /// <summary>
        /// Creates a new instance
        /// </summary>
        /// <param name="renderModel">The Model used to render the asteroid</param>
        /// <param name="collisionModel">The Model used to perform collisions</param>
        public Asteroid(Model renderModel, Model collisionModel) : base(renderModel)
        {
            // we create a non player agent and add it to this asteroid to apply a couple of behaviors
            var nonPlayerAgent = SessionManager.CurrentSession.CreateNonPlayerAgent();
            nonPlayerAgent.Add(new PlaneConstraintBehavior()); // we want the asteroid to keep itself on the Y 0f plane
            nonPlayerAgent.Add(new WrappedScreenBehavior());   // we want the asteroid to get on the other side of the screen when reaching one of its borders.
            Components.Add(nonPlayerAgent);

            // here we see the flexibility and power of the Behavior system: you can add them to whatever game entity you want just like a script.

            CollisionMove = new ConvexHullCollisionMove(this, collisionModel)
                                {
                                    Entity =
                                        {
                                            AngularDamping = 0f,     // we set the damping of the Angular force to 0 since we want the asteroid to continue rotating
                                            LinearDamping = 0f,      // we set the damping of the Linear force to 0 since we want the asteroid to continue moving the same direction
                                            Material =
                                                {
                                                    Bounciness = 1f  // we want the force to be divided between the current asteroid and others when they collide
                                                }
                                        }
                                };
        }
    }
}